
clear all
set more off
cap log close

ssc install unique
    
global dir "/Replication Archive"
cd "${dir}"

global outreg_settings = " label bdec(4) pvalue pdec(3) tex(frag) excel  nor2 nonotes "



***********************************
************* TABLE 3 *************
***********************************

use "${dir}/Data/Federal Committee Assignmnents/committee_assignments_final.dta", clear
keep icpsr2 cycle chamber Party
destring icpsr2, replace
save "temp_party_ALT.dta", replace

use "${dir}/Data/Final Datasets/Final_Data_Director_MC_Level_DEF2.dta", clear

gen donated=(amount_noself>0)
replace donated=donated*1000

replace chairman=0 if chairman==.

unique CompanyID
local unique_company: display %5.4fc `r(unique)' 

collapse (max) donated relevant chairman (first) majority, by(DirectorID cycle icpsr2 chamber)

merge m:1 icpsr2 cycle chamber using "temp_party_ALT.dta"
drop if _m==2
drop _m
drop if Party!=100 & Party!=200
gen Dem=(Party==100)
gen Rep=(Party==200)

erase "temp_party_ALT.dta"

egen double Director_MC=group(DirectorID icpsr2 chamber)
egen double Congress_MC=group(icpsr2 chamber cycle)
egen double Congress_Director=group(DirectorID cycle chamber)

gen relevant_Rep=(relevant==1 & Rep==1)

gen relevant_majority=(relevant==1 & majority==1)

bys Congress_MC: egen chairman_any=max(chairman)

unique DirectorID 
local unique_directors: display %5.4fc `r(unique)' 
unique icpsr2 
local unique_MC: display %5.4fc `r(unique)' 

reghdfe donated relevant_majority relevant, absorb(Director_MC Congress_MC Congress_Director) cluster(Director_MC) keepsingletons compact
su donated if relevant ==0 & majority==0 & e(sample)==1, d
local mean_min: display %5.4fc `r(mean)' 
su donated if relevant ==0 & majority==1 & e(sample)==1, d
local mean_maj: display %5.4fc `r(mean)' 
local effect_min = _b[relevant]/`mean_min'*100
local effect_min: display %5.4fc `effect'
local effect_maj = (_b[relevant]+_b[relevant_majority])/`mean_maj'*100
local effect_maj: display %5.4fc `effect'
outreg2 using "${dir}/Results/Table3", $outreg_settings addtext(Mean Majority, `mean_maj', Mean Minority, `mean_min', Mean Chair, - , Increase Majority, `effect_maj', Increase Minority, `effect_min', Increase Chair, - , Num. Individuals, `unique_directors', Num. Companies, `unique_company', Num. MCs, `unique_MC')  nocons

reghdfe donated relevant_majority relevant_Rep relevant, absorb(Director_MC Congress_MC Congress_Director) cluster(Director_MC) keepsingletons compact
su donated if relevant ==0 & majority==0 & e(sample)==1, d
local mean_min: display %5.4fc `r(mean)' 
su donated if relevant ==0 & majority==1 & e(sample)==1, d
local mean_maj: display %5.4fc `r(mean)' 
local effect_min = _b[relevant]/`mean_min'*100
local effect_min: display %5.4fc `effect'
local effect_maj = (_b[relevant]+_b[relevant_majority])/`mean_maj'*100
local effect_maj: display %5.4fc `effect'
outreg2 using "${dir}/Results/Table3", $outreg_settings addtext(Mean Majority, `mean_maj', Mean Minority, `mean_min', Mean Chair, - , Increase Majority, `effect_maj', Increase Minority, `effect_min', Increase Chair, - , Num. Individuals, `unique_directors', Num. Companies, `unique_company', Num. MCs, `unique_MC')  nocons

drop relevant_majority
gen relevant_majority=(relevant==1 & majority==1 & chairman==0)
gen relevant_chairman=(relevant==1 & majority==1 & chairman==1)

reghdfe donated relevant_chairman relevant_majority relevant, absorb(Director_MC Congress_MC Congress_Director) cluster(Director_MC) keepsingletons compact
su donated if relevant ==0 & majority==0 & e(sample)==1, d
local mean_min: display %5.4fc `r(mean)' 
su donated if relevant ==0 & majority==1 & chairman_any==0 & e(sample)==1, d
local mean_maj: display %5.4fc `r(mean)' 
su donated if relevant ==0 & majority==1 & chairman_any==1 & e(sample)==1, d
local mean_chair: display %5.4fc `r(mean)' 
local effect_min = _b[relevant]/`mean_min'*100
local effect_min: display %5.4fc `effect'
local effect_maj = (_b[relevant]+_b[relevant_majority])/`mean_maj'*100
local effect_maj: display %5.4fc `effect'
local effect_chair = (_b[relevant]+_b[relevant_chairman])/`mean_chair'*100
local effect_chair: display %5.4fc `effect'
outreg2 using "${dir}/Results/Table3", $outreg_settings addtext(Mean Majority, `mean_maj', Mean Minority, `mean_min', Mean Chair, `mean_chair' , Increase Majority, `effect_maj', Increase Minority, `effect_min', Increase Chair, `effect_chair' , Num. Individuals, `unique_directors', Num. Companies, `unique_company', Num. MCs, `unique_MC')  nocons

